<?php
/**
 * Plugin Name: Huu Loi_Notification
 * Plugin URI: 
 * Description: hiển thị nội dung phù hợp
 * Version: 1.0 
 * Author: Huu Loi
 * Author URI: 
 * License: GPLv2 or later // Thông tin license của plugin, nếu không quan tâm thì bạn cứ để GPLv2 vào đây
 */
?>

<?php 
	
function notification_style()
{
	wp_register_style( 'notification_style', plugins_url('notification.css', __FILE__) );	
	wp_enqueue_style( 'notification_style' );
}
add_action('wp_enqueue_scripts','notification_style');

function notification_scripts() {
	global $current_user;

	wp_enqueue_script( 'jquery' );
	wp_register_script( 'notification_script', plugins_url('notification.js', __FILE__) );	

	wp_enqueue_script( 'notification_script' );
	 wp_localize_script( 'notification_script', 'notify_obj', array(
	    'current_url' => plugins_url('source/counter_notify.mp3',__FILE__),
	    'current_user' => $current_user->id,
		'ajaxurl' => admin_url( 'admin-ajax.php' ),

	));
}
add_action('wp_enqueue_scripts','notification_scripts');

function like_notification()
	{

		require_once(dirname(__FILE__)."\model.php" );
		require_once(dirname(__FILE__)."\controller.php" );
		$model = new NotificationModel();
		$controller = new NotificationController($model);
		//$controller->user_header();
		require_once(dirname(__FILE__)."/view.php" );

		$view = new NotificationView($model,$controller);
		return $view->like_notification();

	}
add_shortcode("like-notification","like_notification" );
function comment_notification()
	{

		require_once(dirname(__FILE__)."\model.php" );
		require_once(dirname(__FILE__)."\controller.php" );
		$model = new NotificationModel();
		$controller = new NotificationController($model);
		//$controller->user_header();
		require_once(dirname(__FILE__)."/view.php" );

		$view = new NotificationView($model,$controller);
		return $view->comment_notification();
	}
add_shortcode("comment-notification","comment_notification" );
function image_notification()
	{

		require_once(dirname(__FILE__)."\model.php" );
		require_once(dirname(__FILE__)."\controller.php" );
		$model = new NotificationModel();
		$controller = new NotificationController($model);
		require_once(dirname(__FILE__)."/view.php" );

		$view = new NotificationView($model,$controller);
		return $view->image_notification();
	}
add_shortcode("new-image-notification","new_image_notification" );
function chat_room()
	{

		require_once(dirname(__FILE__)."\model.php" );
		require_once(dirname(__FILE__)."\controller.php" );
		$model = new NotificationModel();
		$controller = new NotificationController($model);
		require_once(dirname(__FILE__)."/view.php" );

		$view = new NotificationView($model,$controller);
		return $view->chat_room();
	}
add_shortcode("chat-room","chat_room" );
add_action( 'wp_ajax_like_clicked', 'like_clicked_notification' );
add_action( 'wp_ajax_nopriv_like_clicked', 'like_clicked_notification' );
function like_clicked_notification()
{
	require_once(dirname(__FILE__)."\model.php" );
	require_once(dirname(__FILE__)."\controller.php" );
	$model = new NotificationModel();
	$controller = new NotificationController($model);
	$controller->like_clicked();
	//require_once(dirname(__FILE__)."/view.php" );
	//$view = new NotificationView($model,$controller);
	//return $view->like_clicked_notification();
}
add_action( 'wp_ajax_comment_submitted', 'comment_submitted_notification' );
add_action( 'wp_ajax_nopriv_comment_submitted', 'comment_submitted_notification' );
function comment_submitted_notification()
{
	require_once(dirname(__FILE__)."\model.php" );
	require_once(dirname(__FILE__)."\controller.php" );
	$model = new NotificationModel();
	$controller = new NotificationController($model);
	$controller->comment_submitted();
	//require_once(dirname(__FILE__)."/view.php" );
	//$view = new NotificationView($model,$controller);
	//return $view->like_clicked_notification();
}
add_action( 'wp_ajax_get_counter', 'get_counter' );
add_action( 'wp_ajax_nopriv_get_counter', 'get_counter' );
function get_counter()
{
	require_once(dirname(__FILE__)."\model.php" );
	require_once(dirname(__FILE__)."\controller.php" );
	$model = new NotificationModel();
	$controller = new NotificationController($model);
	$controller->get_counter();
	//require_once(dirname(__FILE__)."/view.php" );
	//$view = new NotificationView($model,$controller);
	//return $view->like_clicked_notification();
	die();
}
add_action( 'wp_ajax_get_liked_list', 'view_liked_list' );
add_action( 'wp_ajax_nopriv_get_liked_list', 'view_liked_list' );
function view_liked_list()
{
	require_once(dirname(__FILE__)."\model.php" );
	require_once(dirname(__FILE__)."\controller.php" );
	$model = new NotificationModel();
	$controller = new NotificationController($model);
	require_once(dirname(__FILE__)."/view.php" );
	$view = new NotificationView($model,$controller);
	$view->view_liked_list();
	$controller->view_liked_list();
	die();

}
add_action( 'wp_ajax_get_commented_list', 'view_commented_list' );
add_action( 'wp_ajax_nopriv_get_commented_list', 'view_commented_list' );
function view_commented_list()
{
	require_once(dirname(__FILE__)."\model.php" );
	require_once(dirname(__FILE__)."\controller.php" );
	$model = new NotificationModel();
	$controller = new NotificationController($model);
	require_once(dirname(__FILE__)."/view.php" );
	$view = new NotificationView($model,$controller);

	$view->view_commented_list();
	$controller->view_commented_list();
	
	die();

}
?>